package cn.agiledata.bank.barcodepayment.dao;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import cn.agiledata.bank.hibernateBean.BarCodePayTotal;
import com.vnv.infrastructure.logic.IPBHibernate3BaseMgr;

public class BarCodePayTotalDaoImpl extends IPBHibernate3BaseMgr implements
		BarCodePayTotalDao {

	public List getSettleStatusList() {
		String hql ="from Sysbook t where t.id.typeId = 'CHARGE_STATUS'";
		return getHibernateTemplate().find(hql);
	}

	public BarCodePayTotal saveBarCodePayTotal(BarCodePayTotal total) {
				getHibernateTemplate().save(total);
		return total;
	}

	public void updateBarCodePayTotal(BarCodePayTotal total) {
		getHibernateTemplate().update(total);
		
	}

	public BarCodePayTotal getBarCodePayTotalDao(Long id) {
		String hql ="from BarCodePayTotal t where t.id = ?";
		return (BarCodePayTotal)getHibernateTemplate().find(hql,id).get(0);
	}



 public void updateBarCodePayTotalStatus(String id) {
        BarCodePayTotal total = (BarCodePayTotal) getHibernateTemplate().load(BarCodePayTotal.class,new Long(id));
        if (total != null) {
            if (total.getSettleStatus().equals("2")) {
                total.setSettleStatus("3");
                getHibernateTemplate().update(total);
            }
            
        }
    }
    
    public List getChargeList(String id) {
        String hql = "from BarCodePayTotalHis t where t.totalSeq = ?";
        return getHibernateTemplate().find(hql, new Long(id));
    }

	public List getBarCodePayTotals(String batchNo) {
		String hql="from BarCodePayTotal t where t.batchNo = ?";
		return getHibernateTemplate().find(hql, batchNo);
	}
	
	public List getBarCodePayTotals(Date beginDate,Date endDate,String status) {
		String hql="from BarCodePayTotal t " +
				"where 1=1  ";
		List listParam = new ArrayList();
		if(beginDate != null) {
			hql += " and t.createTime >= ? ";
			listParam.add(beginDate);
		}
		if(endDate != null) {
			hql += " and t.createTime <= ? ";
			listParam.add(endDate);
		}
		if(status != null) {
			hql += " t.settleStatus = ? ";
			listParam.add(status);
		}
		
		Object[] param = listParam.toArray();
		
		return getHibernateTemplate().find(hql, param);
	}
}
